﻿using Autofac;
using Microsoft.AspNetCore.Http;
using SX.BaseService.Repository.Core;
using SX.BaseService.Service;
using SX.BaseService.Service.Events;
using SX.BaseService.Service.Implement.Auth;
using SX.BaseService.Service.Implement.SysPermission;
using SX.BaseService.Service.Implement.SysRole;
using SX.BaseService.Service.Interface;
using SX.Core.Auth;
using SX.Core.EventBus.Db;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SX.BaseService.API.Autofac
{
    public class AutofacModule:Module
    {
        public AutofacModule()
        {

        }
        /// <summary>
        /// 加载配置数据
        /// </summary>
        /// <param name="builder">容器绑定器</param>
        protected override void Load(ContainerBuilder builder)
        {
            #region 业务
            builder.RegisterType(typeof(AuthService)).As(typeof(IAuthService)).InstancePerDependency();
            builder.RegisterType(typeof(SysRolePermissionService)).As(typeof(ISysRolePermissionService)).InstancePerDependency();
            builder.RegisterType(typeof(SysRoleService)).As(typeof(ISysRoleService)).InstancePerDependency();
            builder.RegisterType(typeof(SysPermissionService)).As(typeof(ISysPermissionService)).InstancePerDependency();
            builder.RegisterType(typeof(SysUserService)).As(typeof(ISysUserService)).InstancePerDependency();
            builder.RegisterType(typeof(SysOrganizeService)).As(typeof(ISysOrganizeService)).InstancePerDependency();
            builder.RegisterType(typeof(SysDictionaryService)).As(typeof(ISysDictionaryService)).InstancePerDependency();
            builder.RegisterType(typeof(SysConfigService)).As(typeof(ISysConfigService)).InstancePerDependency();
            builder.RegisterType<ProductAddIntegrationEventHandler>().InstancePerDependency();
            #endregion

            #region 仓储
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerDependency();
            #endregion
            #region Core
            builder.RegisterType(typeof(EventLogService)).As(typeof(IEventLogService)).InstancePerDependency();

            builder.RegisterType(typeof(PermissionHandler)).As(typeof(IPermissionHandler)).InstancePerDependency();

            builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();

            builder.RegisterType<LoginInfo>().As<ILoginInfo>().SingleInstance();
            #endregion
        }
    }
}
